import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase="DBshop012_添加商品"
# 登录后台管理系统,地址是"http://localhost/dbshop/admin",
firefox=openBrowser("http://localhost/dbshop/admin")
firefox.get(urlAdmin)
#调用自定义函数进行后台的登录
DBshopLoginAdmin(firefox)
# 进入销售管理中的发货单,
DBshopEnterMenu2(firefox,'商品管理','管理商品')
#点击“添加商品”
firefox.find_element_by_partial_link_text("添加商品").click()
#输入商品名,本店价格
firefox.find_element_by_id("goods_name").send_keys("苹果XR")
firefox.find_element_by_id("goods_shop_price").send_keys("7999")
#处理下拉框，选择“虚拟商品”
from selenium.webdriver.support.select import Select
list=Select(firefox.find_element_by_id("goods_type"))
list.select_by_visible_text("虚拟商品")
#点击保存商品
firefox.find_element_by_xpath('//button[contains(.,"保存商品")]').click()


#断言
firefox.find_element_by_name("goods_name").send_keys("苹果XR")
firefox.find_element_by_xpath("//button").click()
try:
    firefox.find_element_by_link_text("苹果XR")
    writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()